package com.hook3.pianke.activity.base.radiouserbasepager.PrivateRadioViewpagerBase;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.hook3.pianke.R;
import com.hook3.pianke.domain.PrivateRadioInfo;

import java.util.ArrayList;

/**
 * 第一页播放列表
 * Created by HOME on 2015/12/11.
 */
public class PrivateRadioViewpager1 extends PrivateRadioViewpagerBasePager {
    ArrayList<PrivateRadioInfo.PrivateRadioEachContent> privateRadiolist;
    public PrivateRadioViewpager1(Activity activity, ArrayList<PrivateRadioInfo.PrivateRadioEachContent> privateRadiolist){
        super(activity);
        this.privateRadiolist = privateRadiolist;

    }

    ListView listView;
    @Override
    public View initView() {
        View view = View.inflate(activity, R.layout.private_radio_viewpager1,null);
        listView = (ListView) view.findViewById(R.id.lv_private_radio_viewpager1);

        return view;
    }

    public void initData(){
        listView.setAdapter(new ViewPager1Adapter());
    }

    /**
     * 创建listView的adapter
     */
    private class ViewPager1Adapter extends BaseAdapter {
        @Override
        public int getCount() {
            return privateRadiolist.size();
        }

        @Override
        public PrivateRadioInfo.PrivateRadioEachContent getItem(int position) {
            return privateRadiolist.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            ViewHolder holder;
            if(convertView == null){
                holder = new ViewHolder();
                convertView = View.inflate(activity,R.layout.item_private_radio_view_pager1,null);
                holder.tingName = (TextView) convertView
                        .findViewById(R.id.tv_private_radio_view_pager1_list_ting_name);
                holder.authorName = (TextView) convertView
                        .findViewById(R.id.tv_private_radio_view_pager1_list_author);
                convertView.setTag(holder);
            }else{
                holder = (ViewHolder) convertView.getTag();
            }

            PrivateRadioInfo.PrivateRadioEachContent item = getItem(position);
            holder.tingName.setText(item.title);
            holder.authorName.setText(item.playInfo.userinfo.uname);
            return convertView;
        }
    }
    static class ViewHolder{
        TextView tingName;
        TextView authorName;
    }

}
